import { takeEvery, put } from "redux-saga/effects"
import axios from "axios"

function* loadTags() {
  let { data } = yield axios.get("http://localhost:1337/tags")
  console.log('333',data)
  yield put({ type: "loadTagsSuccess", payload: data })
}

function* addTag({ payload }) {
  let { data1 } = yield axios.post("http://localhost:1337/tags", payload)
    let { data } = yield axios.get("http://localhost:1337/tags")
    console.log('333',data)
    yield put({ type: "loadTagsSuccess", payload: data })
    // yield put({ type: "loadTagsSuccess", payload: data })
}

function* delTag({ payload }) {
  let { data1 } = yield axios.delete(`http://localhost:1337/tags/${payload.id}`)
  let { data } = yield axios.get("http://localhost:1337/tags")
  console.log('333',data)
  yield put({ type: "loadTagsSuccess", payload: data })
}

export default function* tagSaga() {
  yield takeEvery("loadTags", loadTags)
  yield takeEvery("addTag", addTag)
  yield takeEvery("delTag", delTag)
}